﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;


namespace WebSite.UserSetting
{
    public partial class RealmNameSet : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadContent();
            }
        }

        #region 提交
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string realmname = txtRealmName.Text.Trim();
            //判断该个性域名是否已经存在
            UsersHelper uhelper = new UsersHelper();
            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "RealmName", realmname);
            int count = uhelper.QueryUsersCountBySearch(c);
            if (count > 0)
            {
                Tools.AlertAndRedirect("该个性域名已经存在，请输入其他", "RealmNameSet.aspx");
                return;
            }
            else
            {
                Users uinfo = UserBase.GetCurrentUser();
                uinfo.RealmName = realmname;
                uhelper.EditUsers(uinfo);
                System.Web.HttpContext.Current.Session["CurrentUser"] = uinfo;//更新session中的值
                Tools.AlertAndRedirect("设置个性域名成功", "RealmNameSet.aspx");
                return;
            }
        }
        #endregion

        #region 加载内容
        private void LoadContent()
        {
            Users uinfo = UserBase.GetCurrentUser();
            string realmname = uinfo.RealmName+"";
            if (string.IsNullOrEmpty(realmname))//不存在
            {
                ulyes.Visible = true;
                ulno.Visible = false;
            }
            else
            {
                ulyes.Visible = false;
                ulno.Visible = true;
                lblRealmName.Text = "http://www.youbewin.com/u/" + realmname + ".aspx";
            }
        }
        #endregion
    }
}